package com.baway.biliclitent.fragment.ZoneType;

import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.baway.biliclitent.R;
import com.bumptech.glide.Glide;

/**
 *   分区详情     描述界面
 *   王培炎
 */

public class RegionDesActivity extends AppCompatActivity implements View.OnClickListener{
    private FragmentManager supportFragmentManager;
    private FrameLayout frame;
    CommentFragment commentFragment;
    SynopsisFragment synopsisFragment;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.regiondesactivity);
        intiView();
        //获取管理者
        supportFragmentManager = getSupportFragmentManager();
        supportFragmentManager.beginTransaction().add(R.id.frame,new SynopsisFragment()).commit();
    }
    private void intiView(){
        //获取id
        frame = (FrameLayout) findViewById(R.id.frame);
        TextView fruit_content_text = (TextView) findViewById(R.id.fruit_content_text);
        TextView fruit_content_text2 = (TextView) findViewById(R.id.fruit_content_text2);
        fruit_content_text.setOnClickListener(this);
        fruit_content_text2.setOnClickListener(this);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        CollapsingToolbarLayout collapsingToolbarLayout =
                (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        ImageView fruitImageView = (ImageView) findViewById(R.id.fruit_image_view);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if(actionBar != null){
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        collapsingToolbarLayout.setTitle("av929");

        fruitImageView.setImageResource(R.drawable.ic_comment);
        //加载图片
        Glide.with(this).load(R.drawable.bg_live_sign_in_banner).into(fruitImageView);
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     *  监听事件
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.fruit_content_text:
                //进行添加Fragment
                if(synopsisFragment == null){
                    synopsisFragment = new SynopsisFragment();
                }
                supportFragmentManager.beginTransaction().replace(R.id.frame,synopsisFragment).commit();

                break;
            case R.id.fruit_content_text2:
                if(commentFragment == null){
                    commentFragment = new CommentFragment();
                }
                supportFragmentManager.beginTransaction().replace(R.id.frame,commentFragment).commit();
                break;
        }
    }
}
